Page({
  data: {
    videoTime: "00:00"
  },

  onReady() {
    this.videoCtx = wx.createVideoContext('myVideo')
  },

  play() {
    this.videoCtx.play()
  },

  pause() {
    this.videoCtx.pause()
  },

  viewTimeUpdate(e) {
    var totalSecond = parseInt(e.detail.currentTime);

    var hour = 0;
    var minute = 0;
    var second = totalSecond;

    var time = "0:0"
    if (second > 59) {
      second = parseInt(totalSecond % 60);
      minute = parseInt(totalSecond / 60);
      if (minute > 59) {
        minute = parseInt(minute % 60);
        hour = parseInt(minute / 60);
        time = this.PrefixZero(hour, 2) + ":" + this.PrefixZero(minute, 2) + ":" + this.PrefixZero(second, 2)
      } else {
        time = this.PrefixZero(minute, 2) + ":" + this.PrefixZero(second, 2)
      }
    } else {
      time = "00:" + this.PrefixZero(second, 2);
    }
    this.setData({
      videoTime : time
    })
  },

  PrefixZero(num, n) {
    return (Array(n).join(0) + num).slice(-n);
  }
})